package com.stylefeng.guns.modular.system.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.constant.factory.PageFactory;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.modular.system.model.Djg;
import com.stylefeng.guns.modular.system.service.IDjgService;
import com.stylefeng.guns.modular.system.warpper.GjgWarpper;

/**
 * 高管持股控制器
 *
 * @author fengshuonan
 * @Date 2018-06-08 15:51:17
 */
@Controller
@RequestMapping("/djg")
public class DjgController extends BaseController {

    private String PREFIX = "/system/djg/";

    @Autowired
    private IDjgService djgService;

    /**
     * 跳转到高管持股首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "djg.html";
    }

    /**
     * 跳转到添加高管持股
     */
    @RequestMapping("/djg_add")
    public String djgAdd() {
        return PREFIX + "djg_add.html";
    }

    /**
     * 跳转到修改高管持股
     */
    @RequestMapping("/djg_update/{djgId}")
    public String djgUpdate(@PathVariable Integer djgId, Model model) {
        Djg djg = djgService.selectById(djgId);
        model.addAttribute("item",djg);
        LogObjectHolder.me().set(djg);
        return PREFIX + "djg_edit.html";
    }
    
    @RequestMapping("/djg_detail/{dm}")
    public String djgUpdate(@PathVariable String dm, Model model) {
        model.addAttribute("gDm",dm);
        return PREFIX + "djg_detail.html";
    }
    
    /**
     * 获取高管持股列表
     */
    @RequestMapping(value = "/list_detail/{gDm}")
    @ResponseBody
    public Object listDetail(@PathVariable String gDm) {
    	Page<Djg> page = new PageFactory<Djg>().defaultPage();
    	List<Map<String, Object>> gdhs = djgService.selectDetailMapsByDm(page,gDm);
    	page.setRecords((List<Djg>) new GjgWarpper(gdhs).warp());
        return super.packForBT(page);
    }

    /**
     * 获取高管持股列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String gDm,String gBdtype,Integer zjc) {
    	Page<Djg> page = new PageFactory<Djg>().defaultPage();
    	List<Map<String, Object>> gdhs = djgService.selectMapsByDm(page,gDm,gBdtype,zjc);
    	page.setRecords((List<Djg>) new GjgWarpper(gdhs).warp());
        return super.packForBT(page);
    }

    /**
     * 新增高管持股
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Djg djg) {
        djgService.insert(djg);
        return SUCCESS_TIP;
    }

    /**
     * 删除高管持股
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer djgId) {
        djgService.deleteById(djgId);
        return SUCCESS_TIP;
    }

    /**
     * 修改高管持股
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Djg djg) {
        djgService.updateById(djg);
        return SUCCESS_TIP;
    }

    /**
     * 高管持股详情
     */
    @RequestMapping(value = "/detail/{djgId}")
    @ResponseBody
    public Object detail(@PathVariable("djgId") Integer djgId) {
        return djgService.selectById(djgId);
    }
}
